/*

Copyright 2009 Nicola Dal Pont

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Version ${MAJOR_VERSION}.${MINOR_VERSION}${BETA_MARK} Build ${BUILD_NUMBER}

*/

package com.astoolkit.workflow
{
	import com.astoolkit.workflow.api.*;
	import com.astoolkit.workflow.constant.TaskStatus;
	import com.astoolkit.workflow.inputfilter.DefaultTaskInputFilterFactory;
	import com.astoolkit.workflow.inputfilter.api.ITaskInputFilterFactory;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.utils.ObjectProxy;
	
	[Bindable]
	public dynamic class WorkflowContext extends EventDispatcher implements IWorkflowContext
	{
		private var _initialized : Boolean;
		private var _status : String;
		private var _variables : ContextVariablesProvider;
		private var _failedTask : IWorkflowTask;
		private var _suspendableListeners : SuspendableListenersRegistry;
		private var _inputFilterFactory : ITaskInputFilterFactory;
		
		private var _runninTask : IWorkflowTask;
		
		public function set runningTask(inTask:IWorkflowTask):void
		{
			_runninTask = inTask;
			
		}
		
		public function get runningTask():IWorkflowTask
		{
			return _runninTask;
		}
		
		
		public function get status() : String
		{
			return _status;
		}
		
		public function set status( inStatus :String ) : void
		{
			_status = inStatus;
			if( _status == TaskStatus.STOPPED )
				_initialized = false;
		}
		
		public function get failedTask() : IWorkflowTask
		{
			return _failedTask;
		}
		
		public function set failedTask( inFailedTask : IWorkflowTask) : void
		{
			_failedTask = inFailedTask;
		}
		
		public function get variables() : ContextVariablesProvider
		{
			return _variables;
		}
		
		public function get suspendableListeners():ISuspendableListenersRegistry
		{
			return _suspendableListeners;
		}
		
		public function get initialized():Boolean
		{
			return _initialized;
		}
		
		
		public function init() : void
		{
			_variables  = new ContextVariablesProvider();
			_failedTask = null;
			_status = TaskStatus.STOPPED;
			_suspendableListeners = new SuspendableListenersRegistry();
			_suspendableListeners.initResumeCallBacks();
			if( !_inputFilterFactory )
				_inputFilterFactory = new DefaultTaskInputFilterFactory();
			_initialized = true;
		}
		
		
		
		public function get inputFilterFactory():ITaskInputFilterFactory
		{
			return _inputFilterFactory;
		}
		
		public function set inputFilterFactory(inValue:ITaskInputFilterFactory):void
		{
			_inputFilterFactory = inValue;
		}
		
	}
}